package de.trebings.gia.entities;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Idea {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String title;

	@Persistent
	private String description;

	@Persistent
	private com.google.appengine.api.datastore.Text descriptionLong;

	@Persistent
	private String fbUserId;

	@Persistent
	private Long userId;

	@Persistent
	private Integer status;

	public static final int STATUS_NEW = 0;
	public static final int STATUS_IN_DISCUSSION = 1;
	public static final int STATUS_IN_PLANNING = 2;
	public static final int STATUS_STARTED = 3;
	public static final int STATUS_FINISHED = 4;

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getFbUserId() {
		return fbUserId;
	}

	public Idea(String title, String description, long userId) {
		this.title = title;
		this.descriptionLong = new com.google.appengine.api.datastore.Text(
				description);
		this.userId = userId;
		this.status = STATUS_NEW;
	}

	public Long getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}

	public String getDescription() {
		if (descriptionLong == null) {
			return "";
		} else {
			return descriptionLong.getValue();
		}
	}

	public void setDescription(String description) {
		this.descriptionLong = new com.google.appengine.api.datastore.Text(
				description);
	}

	public String getDescriptionOld() {
		return description;
	}

	public Integer getStatus() {
		return status;
	}

	public String getStatusDescription() {
		if(status == null) {
			status = STATUS_NEW;
			return "kein Status (Fehler)";
		}
		switch (status) {
		case STATUS_NEW:
			return "Idee ist neu";
		case STATUS_IN_DISCUSSION:
			return "Idee ist in Diskussion";
		case STATUS_IN_PLANNING:
			return "Idee ist in Bearbeitung";
		case STATUS_STARTED:
			return "Idee ist in Umsetzung";
		case STATUS_FINISHED:
			return "Idee ist abgeschlossen";
		default:
			return "unbekannter Status";
		}
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
}
